package com.lemon.smartsafetynew.ui.fragment.record;

import android.app.Dialog;
import android.os.Bundle;
import android.view.View;

import com.lemon.android.http.LemonRequestParams;
import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.RefreshType;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.utils.app.UIHelper;
import com.lemon.smartsafetynew.entity.record.CertificateVo;
import com.lemon.smartsafetynew.entity.User;
import com.lemon.smartsafetynew.entity.me.MeCompanyVo;
import com.lemon.smartsafetynew.entity.record.MetalVo;
import com.lemon.smartsafetynew.net.services.RecordServices;
import com.lemon.smartsafetynew.ui.activity.record.RecordCertificateDetailActivity;
import com.lemon.smartsafetynew.ui.adapter.record.CertificateInfoAdapter;
import com.lemon.smartsafetynew.ui.fragment.base.BasePullToRefreshAddTitleFragment;
import com.lemon.smartsafetynew.util.constants.KeyConstants;
import com.lemon.smartsafetynew.util.user.AccountUtil;

import java.util.ArrayList;
import java.util.List;

import kale.adapter.LemonRcvAdapter;

/**
 * Created by JiangAn on 2018/5/25.
 */

public class RecordCertificateFragment extends BasePullToRefreshAddTitleFragment<CertificateVo, List<CertificateVo>>
        implements RecyclerTClickListener<CertificateVo> {
    private static MetalVo matMetalVo;
    private static MeCompanyVo companyVo;
    private String userId;
    private Dialog dialog;

    public static RecordCertificateFragment newInstance(MeCompanyVo companyVo) {
        Bundle args = new Bundle();
        RecordCertificateFragment fragment = new RecordCertificateFragment();
        args.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void getBaseArguments() {
        super.getBaseArguments();
        Bundle bundle = getArguments();
        if (bundle != null) {
            if (bundle.containsKey(KeyConstants.KEY_COMPANY_VO)) {
                companyVo = (MeCompanyVo) bundle.getSerializable(KeyConstants.KEY_COMPANY_VO);
            }
        }
        User userInfo = AccountUtil.getUser();
        userId = userInfo.getUserId();
    }

    @Override
    protected void initViews() {
        super.initViews();
        llTilte.setVisibility(View.VISIBLE);
        tvTitle.setText(R.string.company_space_count);
    }

    @Override
    public void onPullRefresh() {
        LemonRequestParams params = new LemonRequestParams("");
        params.put("company_id", companyVo.getCompany_id());
        params.put("user_id", userId);
        params.put("pageNum",currentPage);
        params.put("pageSize",pageSize);
        RecordServices.init().getSpecialOperaterInfo(RefreshType.REFRESH, params);
    }

    @Override
    public void onLoadMore() {
        LemonRequestParams params = new LemonRequestParams("");
        params.put("company_id", companyVo.getCompany_id());
        params.put("user_id", userId);
        params.put("pageNum",currentPage);
        params.put("pageSize",pageSize);
        RecordServices.init().getSpecialOperaterInfo(RefreshType.LOAD_MORE, params);
    }

    @Override
    public boolean goRefreshOnCreate() {
        return true;
    }

    @Override
    public LemonRcvAdapter<CertificateVo> getLemonAdapter() {
        return new CertificateInfoAdapter(mDataList, this);
    }

    @Override
    public String getHttpTag() {
        return KeyConstants.URL_GET_SPECIAL_OPERATOR_INFO_LIST;
    }

    @Override
    public void onDataList(List<CertificateVo> data) {
        if(data != null && data.size() > 0) {
            tvTitleCount.setText("" + data.get(0).getTotalcount());
        }else{
            tvTitleCount.setText("0");
        }
    }

    @Override
    public void onItemClick(CertificateVo data, int position) {
        Bundle bundle = new Bundle();
        bundle.putSerializable(KeyConstants.KEY_SPECIAL_OPERATOR_VO, data);
        bundle.putBoolean("isShowReturn",companyVo.getIfShowReturn());
        UIHelper.showActivity(getmContext(), bundle, RecordCertificateDetailActivity.class);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();

    }
}




